import App from './App'

// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false

App.mpType = 'app'
import uView from "./uni_modules/uview-ui";
Vue.use(uView);

// #ifdef H5
// var host = window.location.prohttp://wx.tille168.com/static/static/my/bg.pngtocol+'//'+window.location.host;
var host = 'http://www.yndzfl.cn/'
Vue.prototype.host = host;
Vue.prototype.host_base = host; 
// #endif

// #ifdef MP-WEIXIN
Vue.prototype.host = 'http://www.yndzfl.cn/';
Vue.prototype.host_base = 'http://www.yndzfl.cn/'; 
// #endif

// #ifdef APP-PLUS
Vue.prototype.host = 'http://www.yndzfl.cn/';
Vue.prototype.host_base = 'http://www.yndzfl.cn/'; 
// #endif

Vue.prototype.showError = function (msg, callback) {
    uni.showModal({
      title: '友情提示',
      content: msg.toString(),
      showCancel: false,
      success: function (res) {
        callback && callback();
      }
    });
}

Vue.prototype.showMs = function (msg, callback,Cancel=false,cancelback) {
    uni.showModal({
      content: msg.toString(),
      showCancel: Cancel,
      success: function (res) {
		if(res.confirm){
			callback && callback();
		}else{
			cancelback && cancelback();
		}
      }
    });
}

Vue.prototype.Toast = function (msg,icon = 'success', callback) {
    uni.showToast({
    	title:msg.toString(),
		icon:icon,
		success: function (res) {
		  callback && callback();
		}
    });
}
Vue.prototype.fq_ajax = function(url, data, success, method,fail, complete){
	var headers = {'Content-Type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest'};
	var token = uni.getStorageSync('token');
	var openid = uni.getStorageSync('OPENID');
	console.log(token)
	if(openid){
		if (method == "post") {
			
			data.openid = openid
		} else {
			
			data.openid = openid
		}
	}
	if (token) {
		if (method == "post") {
			data.token = token
		} else {
			data.token = openid
		}
	}
	uni.showLoading({ title:'玩命加载中...' });
	uni.request({
		url:this.host + url,
		data:data,
		header: headers,
		method: method,
		success: (res) => {
			console.log(res)
			uni.hideLoading();
			if (res.statusCode !== 200) {			
			  this.showError('网络请求出错'+res.statusCode);
			  return false;
			}else if(res.data.code == -1){
				this.showError(res.data.msg, function () {
				      fail && fail(res);
				});
			}else{
				success && success(res.data);
				// if (res.data.status === 5) {
				//   	this.login(res.data.message);	
				// 	return false;
				// } else if (res.data.status === -100) {
				//    this.showError(res.data.msg, function () {
				//       fail && fail(res);
				//    });
				//    uni.reLaunch({
				//    	url:'/pages/login/login'
				//    })
				//   return false;
				// }else if(res.data.status === -1){
				// 	this.showError(res.data.msg, function () {
				// 	   fail && fail(res);
				// 	});
				// } else {
				//   success && success(res.data);
				// }
			}
		},
		fail:  (res)=> {
			this.showError(res.errMsg, function () {
			     fail && fail(res);
			});
		},
		complete:  (res)=> {
			complete && complete(res);
		}
	})
}
Vue.prototype.fq_post = function(url, data, success = true,fail, complete){
	this.fq_ajax(url, data, success, 'POST',fail, complete);
}
Vue.prototype.fq_get = function(url, data, success = true,fail, complete){
	this.fq_ajax(url, data, success, 'GET',fail, complete);
}
Vue.prototype.fq_edit = function(url, data, success = true,fail, complete){
	this.fq_ajax(url, data, success, 'PUT',fail, complete);
}
Vue.prototype.fq_del = function(url, data, success,fail, complete){
	this.fq_ajax(url, data, success, 'DELETE',fail, complete);
}

const app = new Vue({
  ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif